package com.zhj.agent.matcher;

import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

import java.util.Objects;

/**
 * 类型匹配器工厂对象
 */
public class TypeMatcherFactory {

    /**
     * Instance
     *
     * @param <V>    parameter
     * @param <T>    parameter
     * @param clz    clz
     * @param params params
     * @return the t
     * @since 0.0.1
     */
    public static <V, T extends TypeMatcher<V>> ElementMatcher<TypeDescription> instance(Class<T> clz, V params) {
        Objects.requireNonNull(clz, "匹配器类型不能为空");
        T t = null;
        try {
            t = clz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
            throw new IllegalArgumentException("类型匹配器实例化失败:" + clz);
        }
        return t.load(params);
    }

}
